
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Text;

using Swaf;
using Swaf.BizObj;
using Swaf.Gui;
using Swaf.Gui.AspNet2;

using Syrinx.Gui;
using System.Web.UI.WebControls;

namespace FilterSort.Gui.AspNet
{
    public class ConfirmSaveOverwritePopup : Swaf.Gui.AspNet2.UserControl, IActionParamDisplay
    {
        protected IBizObj m_currentBizObj;
        protected string m_sessionId;
        protected string m_sessionGroupName;

        public void setupForAction(IAction action)
        {
            if (action.ParentProcess != null)
            {
                //m_currentBizObj = ((Swaf.Gui.IBizObjBizProcess)action.ParentProcess).SelectedBizObj;
                m_sessionId = string.Format("{0}-Data", action.ParentProcess.Id);
                m_sessionGroupName = string.Format("{0}-GroupName",action.ParentProcess.Id);

                m_currentBizObj = (IBizObj)Swaf.Application.currentApp.sessionData[m_sessionId];
            }
            createControls();
        }

        public object getActionParam()
        {
            if (m_currentBizObj != null)
            {
                RadioButtonList m_saveOption = (RadioButtonList)FindControl("saveOption");
                TextBox txt = (TextBox)FindControl("name");
                CheckBox isCompanyLvl = (CheckBox)FindControl("isCompanyLevel");

                bool isNew = true;
                foreach (ListItem item in m_saveOption.Items)
                {
                    if (item.Selected)
                    {
                        isNew = (item.Value == "true" ? true : false);
                        break;
                    }
                }

                m_currentBizObj.isNew = isNew;

                m_currentBizObj.put("name", txt.Text);
                m_currentBizObj.put("isCompanyLevel", isCompanyLvl.Checked);
                string groupName = (string)Swaf.Application.currentApp.sessionData[m_sessionGroupName];
                m_currentBizObj.put("groupName", groupName);
            }

            return m_currentBizObj;
        }

        protected override bool createControls()
        {
            bool rc = base.createControls();

            // initialized the value of our controls
            TextBox txt = (TextBox)FindControl("name");
            txt.Text = (string)m_currentBizObj.get("name");

            CheckBox isCompanyLvl = (CheckBox)FindControl("isCompanyLevel");
            isCompanyLvl.Checked = (bool)m_currentBizObj.get("isCompanyLevel");

            return rc;
        }

    }
}